from dataclasses import dataclass

from flask import Flask, Blueprint
from injector import inject

from internal.handler import AppHandler, app_handler


@inject
@dataclass
class Router:
    app_handler: AppHandler

    # def __init__(self, app_handler: AppHandler):
    #     self.app_handler = app_handler
    # 使用dataclass简化这里的注解inject注入时,需要在构造函数中这里声明类型与绑定 

    # 注册路由
    def register_router(self, app: Flask):
        # 1.创建一个蓝图
        bp = Blueprint("llmops", __name__, url_prefix="")

        # 2.将url与对应的控制器方法绑定

        bp.add_url_rule('/ping', methods=["GET"], view_func=self.app_handler.ping)
        bp.add_url_rule('/app/completion', methods=["POST"], view_func=self.app_handler.completion)
        bp.add_url_rule('/app',methods=["POST"],view_func=self.app_handler.create_app)
        bp.add_url_rule('/app/<uuid:id>',view_func=self.app_handler.get_app)
        bp.add_url_rule('/app/<uuid:id>',methods=["POST"],view_func=self.app_handler.update_app)
        bp.add_url_rule('/app/<uuid:id>/delete',methods=["POST"],view_func=self.app_handler.delete_app)
        # 3.在应用上去注册蓝图
        app.register_blueprint(bp)
